<?php
/**
 * BootAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using BootAdmin.
 *
 * @Author G.r<root@BootAdmin.com>
 */

declare (strict_types=1);

namespace app\admin\controller;

use app\admin\Base;
use app\admin\logic\FileLogic;
use app\common\model\File;
use app\common\service\Upload;
use think\Exception;
use think\facade\Filesystem;

/**
 * 公共方法
 */
class Ajax extends Base
{
    public array $notNeedLogin = ['index', 'file'];

    public array $notNeedRight = ['upload', 'dict'];

    public function index()
    {
        $model = new File();
        $row = $model->find(15);
        $path = str_replace("/",DIRECTORY_SEPARATOR, Filesystem::disk('public')->path($row->path));
        var_dump(getVideoCover($path));
    }

    /**
     * 文件上传
     */
    public function upload()
    {
        try {
            $cid = $this->request->post('cid', 0);
            $result = Upload::file($cid, $this->adminId);
            return $this->success('上传成功', $result);
        } catch (Exception $e) {
            return $this->fail($e->getMessage());
        }
    }

    /**
     * 文件预览
     */
    public function file()
    {
        $param = $this->request->param();
        return (new FileLogic())->getFile($param);
    }

    /**
     * 获取字典
     */
    public function dict()
    {
        $code = $this->request->param('code');
        return $this->success('获取成功', get_dict($code));
    }
}